﻿using System.Collections.ObjectModel;

namespace Sidvall.Security
{
    public static class Operations
    {
        #region Public Members

        public const string DeleteItems = "DeleteItems";
        public const string NewItems = "NewItems";
        public const string GetItems = "GetItems";
        public const string GetItemsMetadata = "GetItemsMetadata";
        public const string AddItems = "AddItems";
        public const string UpdateItems = "UpdateItems";
        public const string UpdateItemValues = "UpdateItemValues";
        public const string SaveItems = "SaveItems";
        public const string Execute = "Execute";

        #region GetOperation

        public static string GetOperation(Sidvall.Data.DataRowState state)
        {
            switch (state)
            {
                case Sidvall.Data.DataRowState.Modified:
                    return UpdateItems;
                case Sidvall.Data.DataRowState.Added:
                    return AddItems;
                case Sidvall.Data.DataRowState.Deleted:
                    return DeleteItems;
                default:
                    return null;
            }
        }

        #endregion
        #region GetOperations

        public static Collection<string> GetOperations()
        {
            return GetOperations(OperationTypes.All);
        }
        public static Collection<string> GetOperations(OperationTypes operationTypes)
        {
            var items = new System.Collections.Generic.List<string>();
            if ((operationTypes & OperationTypes.DeleteItems) == OperationTypes.DeleteItems)
                items.Add(DeleteItems);
            if ((operationTypes & OperationTypes.NewItems) == OperationTypes.NewItems)
                items.Add(NewItems);
            if ((operationTypes & OperationTypes.GetItems) == OperationTypes.GetItems)
                items.Add(GetItems);
            if ((operationTypes & OperationTypes.GetItemsMetadata) == OperationTypes.GetItemsMetadata)
                items.Add(GetItemsMetadata);
            if ((operationTypes & OperationTypes.AddItems) == OperationTypes.AddItems)
                items.Add(AddItems);
            if ((operationTypes & OperationTypes.UpdateItems) == OperationTypes.UpdateItems)
                items.Add(UpdateItems);
            if ((operationTypes & OperationTypes.UpdateItemValues) == OperationTypes.UpdateItemValues)
                items.Add(UpdateItemValues);
            if ((operationTypes & OperationTypes.SaveItems) == OperationTypes.SaveItems)
                items.Add(SaveItems);
            if ((operationTypes & OperationTypes.Execute) == OperationTypes.Execute)
                items.Add(Execute);
            return new System.Collections.ObjectModel.Collection<string>(items);
        }

        #endregion

        #endregion
    }
}
